import {
  getShareResource,
  sendPlaylist,
  sendSong,
  sendText,
  setEventForward
} from "@/api/share/index";
import {Notify, Toast} from "vant";
import {sendAlbum} from "@/api/album/index";
import {setEventDel} from "../../api/share/index.js";

const shareState = {}
const shareAction = {
  // 分享到动态分享歌单的id, msg分享歌单的话，type分享的是歌单歌曲还是mv等
  getShareResource(params) {
    return getShareResource(params).then(res => {
      const { code } = res
      if (Number(code) === 200) {
        Notify({
          message: '分享成功',
          background: '#ffe1e1',
          color: '#ad0000'
        })
        return code
      }
    })
  },
  // 分享到私信
  sendPlaylist(params, type) {
    const sendFn = {
      'text': () => {
        return sendText(params).then(res => {
          console.log(res)
          const { code } = res
          if (Number(code) === 200) {
            Notify({
              message: '分享成功',
              background: '#ffe1e1',
              color: '#ad0000'
            })
            this.getMsgPrivate(0 , 'msg')
            return code
          }
        })
      },
      // 分享歌单私信 我的id, 用户user_ids多个id字符串分割, msg携带信息 playlist歌单id { user_ids: '', id: '', msg: '', playlist: '' }
      'playlist': () => {
        return sendPlaylist(params).then(res => {
          const { code } = res
          if (Number(code) === 200) {
            Notify({
              message: '分享成功',
              background: '#ffe1e1',
              color: '#ad0000'
            })
            return code
          }
        })
      },
      // 分享歌曲私信 我的id, 用户user_ids多个id字符串分割, msg携带信息 { user_ids: '', id: '', msg: ''}
      'song': () => {
        return sendSong(params).then(res => {
          const { code } = res
          if (Number(code) === 200) {
            Notify({
              message: '分享成功',
              background: '#ffe1e1',
              color: '#ad0000'
            })
            return code
          }
        })
      },
      // 专辑
      'album': () => {
        sendAlbum(params).then(res => {
          const { code } = res
          if (Number(code) === 200) {
            Notify({
              message: '分享成功',
              background: '#ffe1e1',
              color: '#ad0000'
            })
            return code
          }
        })
      }
    }
    sendFn && sendFn[type] && sendFn[type]()
  },
  // 转发动态
  forwardingDynamicFn(params) {
   setEventForward(params).then(res => {
      const {code} = res
      if (Number(code) === 200){
        Toast('转发成功')
      }
    })
  },
  // 删除用户动态
  setEventDel(id) {
    setEventDel(id).then(res => {
      console.log(res)
    })
  }
}
const shareGetters = {}

export {
  shareState,
  shareGetters,
  shareAction
}
